import axios, { AxiosRequestConfig } from 'axios'
import { request, response } from './interceptor'

const config: AxiosRequestConfig = {
  baseURL: '/api',
  // timeout: 10000, // 默认 10s
}

const $http = axios.create(config)

// 加载 axios 拦截器
// 请求拦截器
$http.interceptors.request.use(
  (config) => request.onFulfilled(config),
  (err) => request.onRejected(err)
)

// 响应拦截器
$http.interceptors.response.use(
  (res) => response.onFulfilled(res),
  (err) => response.onRejected(err)
)

export default $http
